/**
 * 
 */
package com.base.myproject.client.ui.celleditor;

import com.base.myproject.client.ui.BaseFileUploadDialog;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.HiddenField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;

/**
 * @author zgw 2009-8-7 下午05:09:08 javazgw@gmail.com
 */
public class BaseImageCCRG extends CellEditor implements GridCellRenderer {

	static HiddenField bcb = new HiddenField();

	public static final int UPLOADMODE = 1;
	public static final int LOOKIMAGEMODE = 2;
	public static final int HTMLLINKMODE = 4;
	public static final int SOUNDMODE = 8;
	int mode = 0;

	public BaseImageCCRG(int mode) {

		super(bcb);
		this.mode = mode;
		init();

	}

	void init() {
		/*
		 * SelectionListener sl = new SelectionListener<ButtonEvent>(){
		 * 
		 * @Override public void componentSelected(ButtonEvent ce) {
		 * 
		 * 
		 * com.base.myproject.client.ui.BaseFileUploadDialog.getInstance().show()
		 * ; }};
		 */

	}

	public int getMode() {
		return mode;
	}

	public void setMode(int mode) {
		this.mode = mode;
	}

	@Override
	public Object render(final ModelData model, final String property,
			ColumnData config, final int rowIndex, final int colIndex,
			ListStore store, Grid grid) {
		

		//System.out.println("++" + rowIndex + " colIndex=" + colIndex);
		HorizontalPanel hp = new HorizontalPanel();
		Button uploadbutton = new Button("");
		Button lookimagebutton = new Button("");
		Button htmllinkbutton = new Button("");
		Button soundbutton = new Button("");
		uploadbutton.setToolTip("上传");
		uploadbutton.setIconStyle("uploadicon");
		lookimagebutton.setToolTip("看图");
		lookimagebutton.setIconStyle("imageicon");
		htmllinkbutton.setToolTip("超级连接");
		htmllinkbutton.setIconStyle("htmllinkicon");
		soundbutton.setToolTip("多媒体");
		soundbutton.setIconStyle("soundicon");
		if ((mode & UPLOADMODE) == UPLOADMODE) {
			hp.add(uploadbutton);
		}
		if ((mode & LOOKIMAGEMODE) == LOOKIMAGEMODE) {
			hp.add(lookimagebutton);
		}
		if ((mode & HTMLLINKMODE) == HTMLLINKMODE) {
			hp.add(htmllinkbutton);
		}
		if ((mode & SOUNDMODE) == SOUNDMODE) {
			hp.add(soundbutton);
		}
		uploadbutton.addSelectionListener(new SelectionListener<ButtonEvent>() {

			@Override
			public void componentSelected(ButtonEvent ce) {
				//System.out.println(model.get(property));
				//System.out.println("------" + rowIndex + " colIndex="
					//	+ colIndex);

				BaseFileUploadDialog bf = com.base.myproject.client.ui.BaseFileUploadDialog.getInstance()
						;
				bf.setServletPath("gupld?zgw=uploadbutton&zgw3=2");
				bf.show();
			}

		});
		lookimagebutton.addSelectionListener(new SelectionListener<ButtonEvent>() {

			@Override
			public void componentSelected(ButtonEvent ce) {
				//System.out.println(model.get(property));
				//System.out.println("------1" + rowIndex + " colIndex="
				//		+ colIndex);

				com.base.myproject.client.ui.BasePopupImage.getInstance().show(model.get(property).toString());
			}

		});
		htmllinkbutton.addSelectionListener(new SelectionListener<ButtonEvent>() {

			@Override
			public void componentSelected(ButtonEvent ce) {
				//System.out.println(model.get(property));
				//System.out.println("------2" + rowIndex + " colIndex="
				//		+ colIndex);

			}

		});
		soundbutton.addSelectionListener(new SelectionListener<ButtonEvent>() {

			@Override
			public void componentSelected(ButtonEvent ce) {
				//System.out.println(model.get(property));
				//System.out.println("------3" + rowIndex + " colIndex="
				//		+ colIndex);
				BaseFileUploadDialog bf = com.base.myproject.client.ui.BaseFileUploadDialog.getInstance()
				;
		bf.setServletPath("gupld?zgw=soundbutton&zgw3=soundbutton2");
		bf.show();
		
			}

		});
		// hp.add(new Button("d"));
		return hp;
		// return new Html("<a>html</a>");
	}
	//
	// public Object preProcessValue(Object value) {
	//
	//
	// return B2;
	// // return combobox.getValue();
	//
	// }
	//
	// @Override
	// public Object postProcessValue(Object value) {
	//	
	//
	// return B2;
	//
	// }
}
